package com.test.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 消息类型
 *
 * @author sangkuofeng
 * @date 2023/11/12 00:02
 */
public enum MessageType {
    SUBSCRIBE("subscribe"),
    READ("read"),
    READ_STRING("readString"),
    WRITE_STRING("writeString"),
    BEEP("beep"),
    WRITE_CARD_NUMBER("writeCardNumber");

    private String code;

    MessageType(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public static MessageType getTypeByCode(String code) {
        Optional<MessageType> optional = Arrays.stream(MessageType.values()).filter(item -> StringUtils.equals(code, item.getCode())).findFirst();
        return optional.isPresent() ? optional.get() : null;
    }

}
